/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Game;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.event.*;
import javax.swing.*;

import util.*;
import input.*;
import graphics.ScreenManager;
import graphics.NullRepaintManager;

/**
 *
 * @author Yati
 */
public class IngameMenu extends JFrame implements ActionListener{

    private JButton resume,quit;
    private String stateChange;
    
    public final String QUIT="QUIT";
    public final String RESUME="RESUME";
    
    public IngameMenu(util.ResourceManager resourceManager){
        

        
        NullRepaintManager.install();
        stateChange=null;
        
        resume=createButton("Resume", "Resume game", resourceManager.loadImage("menu/play.png"));
        quit=createButton("Quit", "Exit game", resourceManager.loadImage("menu/quit.png"));
        
        setUndecorated(true);
        //setBackground(null);
        setFocusable(false);
        
        Container cont=this.getContentPane();
        if (cont instanceof JComponent) {
            ((JComponent)cont).setOpaque(false);
        }
        
        cont.setLayout(new FlowLayout(FlowLayout.CENTER));
        cont.add(resume);
        cont.add(quit);
        
        pack();
        //setVisible(false);
        //setEnabled(false);
        
        
        validate();
    }
    
    public void showUI(){
    
        setVisible(true);
        setEnabled(true);
    }
    
        /**
        Creates a Swing JButton. The image used for the button is
        located at "../images/menu/" + name + ".png". The image is
        modified to create a "default" look (translucent) and a
        "pressed" look (moved down and to the right).
        <p>The button doesn't use Swing's look-and-feel and
        instead just uses the image.
    */
    public JButton createButton(String name, String toolTip,Image image) {
        
        // load the image
        //String imagePath = "images/menu/" + name + ".png";
        //ImageIcon iconRollover = new ImageIcon(imagePath);
        ImageIcon iconRollover=new ImageIcon(image);
        int w = iconRollover.getIconWidth();
        int h = iconRollover.getIconHeight();

        // get the cursor for this button
        Cursor cursor =
            Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);

        // make translucent default image
        BufferedImage imageTran=new BufferedImage(image.getWidth(null),image.getHeight(null),BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = (Graphics2D)imageTran.getGraphics();
        Composite alpha = AlphaComposite.getInstance(
            AlphaComposite.SRC_OVER, .5f);
        g.setComposite(alpha);
        g.drawImage(iconRollover.getImage(), 0, 0, null);
        g.dispose();
        ImageIcon iconDefault = new ImageIcon(imageTran);

        // make a pressed image
        imageTran = new BufferedImage(w,h,BufferedImage.TYPE_INT_ARGB);
        g = (Graphics2D)imageTran.getGraphics();
        g.drawImage(iconRollover.getImage(), 2, 2, null);
        g.dispose();
        ImageIcon iconPressed = new ImageIcon(imageTran);

        // create the button
        JButton button = new JButton();
        button.addActionListener(this);
        button.setIgnoreRepaint(true);
        button.setFocusable(false);
        button.setToolTipText(toolTip);
        button.setBorder(null);
        button.setContentAreaFilled(false);
        button.setCursor(cursor);
        button.setIcon(iconDefault);
        button.setRolloverIcon(iconRollover);
        button.setPressedIcon(iconPressed);

        return button;
    }
    
    public void actionPerformed(ActionEvent e){
        
        if(e.getSource()==resume){
            
            stateChange=RESUME;
            
        }else
        if(e.getSource()==quit){
            stateChange=QUIT;
        }
    }
    
    public String getStateChange(){
        return stateChange;
    }
    
    public void reset(){
        stateChange=null;
    }
    
    
}
